package com.atguigu.gmall.product;

import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.util.ClassUtils;

/**
 * @author: 李旭
 * @create: 2021-09-29 12:02
 **/
public class FastDFSDemo {


    //文件上传
    public static void main(String[] args) throws Exception{
        String path = ClassUtils.getDefaultClassLoader().getResource("fdfs_client.conf").getPath();
        //0:设置配置文件的位置进行读取  init IO流 读取配置文件 必须是绝对路径
        ClientGlobal.init(path);
        //1:连接Tracker跟踪器
        TrackerClient trackerClient = new TrackerClient();
        //2:返回值存储节点地址
        TrackerServer trackerServer = trackerClient.getConnection();
        //3:连接存储节点
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,null);
        //4:上传文件 500M
        String fileId = storageClient1.upload_file1(
                "D:\\尚品汇商城\\资料\\图片\\华为mate30\\4e9924f5f9a516b4.jpg",
                "jpg",
                null
        );
        System.out.println("http://192.168.200.138:8080/" + fileId);

        //http://192.168.200.138:8080/group1/M00/00/00/wKjIimFUeDaABOl_AAOduv80spo419.jpg
    }
}
